<?php
/**
 * Created by PhpStorm.
 * User: 图图
 * Date: 2021-6-8
 * Time: 16:29
 */

namespace app\api\controller;
use app\common\controller\Api;
use app\common\model\Factor;
use app\common\model\Fenorder;
use app\common\model\Store;
use app\common\controller\Smscm;
/**
 * 前台首页控制器
 * @package app\index\controller
 */
class SendSms extends Home
{
    public $noNeedLogin = ['register_send'];


    /**
     * 注册发送手机验证码
     */
    public function register_send()
    {
        if ($this->request->isPost()) {
            $getPhone = $this->request->post('phone');
            $type = $this->request->post('type');
            if(empty($getPhone)){
                $this->result('请填写手机号','',204);
            }
            if(empty($type)){
                $this->result('缺少类型','',204);
            }
            if(preg_match("/^1[34578]\d{9}$/", $getPhone)){
                $sms = new Smscm();
                //$code  = $sms->sms_rand();
                $code  = 123456;
                //注册短信
                if($type == 1){
                    $content = "尊敬的用户，您的验证码是".$code;
                    $res = $sms->sendsms($getPhone,$content,'1',$code);
                }elseif($type == 2){
                    $content = "尊敬的用户，您的验证码是".$code.'验证码只能用户找回密码';
                    $res = $sms->sendsms($getPhone,$content,'2',$code);
                }elseif($type == 3){
                    $content = "尊敬的用户，您的验证码是".$code;
                    $res = $sms->sendsms($getPhone,$content,'3',$code);
                }else{
                    $this->result('无效的请求','',204);
                }
                if($res == true){
                    $this->result('短信发送成功','',200);
                }
                $this->result('短信发送失败','',204);
            }
            $this->result('请填写正确的手机号','',204);
        }
    }
}
